package cn.itsource.shiro.utils;

import cn.itsource.crm.domain.Employee;
import org.apache.shiro.SecurityUtils;

import javax.security.auth.Subject;

/**
 * 存取当前登录用户
 *
 * @author xjh
 * @date 2020/3/31 18:06
 */
public class LoginUserUtil {

    private static final String CURRENT_LOGIN_USER = "loginUser";

    /**
     * 设置当前登录用户
     *
     * @param employee
     */
    public static void setUser(Employee employee) {
        /*获取当前登录用户的session,把用户存放到session中*/
        SecurityUtils.getSubject().getSession().setAttribute(CURRENT_LOGIN_USER, employee);
    }

    /**
     * 获取当前登录用户
     *
     * @return employee
     */
    public static Employee getUser() {
       return (Employee) SecurityUtils.getSubject().getSession().getAttribute(CURRENT_LOGIN_USER);
    }

}